import axios from './axios'
import qs from 'qs'
import {
    baseUrl
} from '@/config/config'

/**
 * 代理管理列表
 * @param {*} params 
 * @returns 
 */
export const getAgentList = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/agent/info?' + qs.stringify(params),
            method: 'get'
        }).then(res => {
            resolve(res.data)
        }).catch(error => {
            reject(error)
        })
    })
}

/**
 * 新增代理
 * @param {*} params 
 * @returns 
 */
export const addAgent = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/agent/info',
            method: 'POST',
            data: params
        }).then(res => {
            var data = res.data
            resolve(data)
        }).catch(error => {
            reject(error)
            // console.log(error)
        })
    })
}

/**
 * 编辑代理
 * @param {*} params 
 * @returns 
 */
 export const updateAgent = (params) => {
    return new Promise((resolve, reject) => {
        axios({
            url: baseUrl + '/api/agent/info',
            method: 'PUT',
            data: params
        }).then(res => {
            var data = res.data
            resolve(data)
        }).catch(error => {
            reject(error)
            // console.log(error)
        })
    })
}

/**
 * 查询推荐人是否存在
 * @returns 
 */
export const checkAgent = (params) => {
    return new Promise((resolve, reject) => {
      axios({
        url: baseUrl + '/api/check/agent/' + params.name,
        method: 'get'
      }).then(res => {
        var data = res.data
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
}

/**
 * 查询推荐人是否存在
 * @returns 
 */
 export const getAgentUserList = (custId) => {
    return new Promise((resolve, reject) => {
      axios({
        url: baseUrl + '/api/get/agent/user',
        method: 'get'
      }).then(res => {
        var data = res.data
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
}

/**
 * 修改代理人用户状态
 */
export const updateAgentState = (custId) => {
    return new Promise((resolve, reject) => {
      axios({
        url: baseUrl + '/api/update/agent/user/' + custId,
        method: 'get'
      }).then(res => {
        var data = res.data
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
}

/**
 * 修改代理人用户状态
 */
 export const refushAgent = (custId) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/refush/agent/user/linp',
      method: 'get'
    }).then(res => {
      var data = res.data
      resolve(data)
    }).catch(error => {
      reject(error)
    })
  })
}

/**
 * 导出
 */
 export const downloadData = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/api/down/load/data',
      method: 'get',
      params: params,
      responseType: 'blob'
    }).then(res => {
      var data = res.data
      resolve(data)
    }).catch(error => {
      reject(error)
    })
  })
}
